package com.yoga.admin.api;

/**
 * Created by chenjin on 2020/9/19.
 */
public class T  implements Runnable{

     private static Object obj=new Object();

        public static  Integer i=1;

        public Integer add(){
            synchronized  (this) {
                i = i + 1;
                if (i == 3 || i == 4) {
                    try {
                        Thread.sleep(2 * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

            System.out.println(i);
            return i;
        }

        @Override
        public void run() {
            add();
        }


    public static void main(String[] args) {
        T t= new T();

        new Thread(t).start();
        new Thread(t).start();
        new Thread(t).start();
        new Thread(t).start();

    }

}
